package com.stupro.cjlu.bo;

import com.stupro.cjlu.constant.UserType;
import com.stupro.cjlu.entity.Admain;
import com.stupro.cjlu.entity.Students;
import com.stupro.cjlu.entity.Teacher;
import lombok.Data;

@Data
public class UserInfoBO {
    //用户的ID
    private Integer id;
    //用户账号
    private String username;
    //用户密码
    private String password;
    //用户类型
    private Integer userType;
    //用户权限
    private Integer permission = 0;

    public UserInfoBO() {
    }

    private UserInfoBO(Integer id, String username, String password, Integer userType) {
        this(id, username, password, userType, 0);
    }

    private UserInfoBO(Integer id, String username, String password, Integer userType, Integer permission) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.userType = userType;
        this.permission = permission;
    }

    public static UserInfoBO fromStudent(Students students) {
        if (students == null) {
            return null;
        }
        return new UserInfoBO(students.getStuID(), students.getStuUserName(), students.getStuPwd(), UserType.STUDENT);
    }

    public static UserInfoBO fromTeacher(Teacher teacher) {
        if (teacher == null) {
            return null;
        }
        return new UserInfoBO(teacher.getTeaID(), teacher.getTeaUserName(), teacher.getTeaPwd(), UserType.TEACHER);
    }

    public static UserInfoBO fromAdmin(Admain admain) {
        if (admain == null) {
            return null;
        }
        return new UserInfoBO(admain.getAdID(), admain.getAdUserName(), admain.getAdPwd(), UserType.ADMIN);
    }
}
